package com.jl.commons.utils;


import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.jl.commons.excel.DeviceExcel;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 导出设excel数据
 */
public class ExportExcel {


    /**
     * 导出设备信息的excel
     * @return
     */
    public static String exportDeviceExcel(){

        OutputStream out = null;
//
        try {
            out = new FileOutputStream("E:/IdeaProject/device/src/main/webapp/data/dataFile/file/77.xlsx");
            ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);
            //写第一个sheet, sheet1  数据全是List<String> 无模型映射关系
            Sheet sheet1 = new Sheet(1, 0,DeviceExcel.class);
            sheet1.setSheetName("第一个sheet");
            List<DeviceExcel> list = new ArrayList<DeviceExcel>();
            Date now = new Date();
            for(int i =0;i<10;i++){
                DeviceExcel deviceExcel = new DeviceExcel("name"+i,"desc"+i,"number"+i,"model"+i,"producer"+i,"line"+i,now,now);
                list.add(deviceExcel);
            }
            writer.write(list, sheet1);
            writer.finish();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }



        return null;
    }

    public static void getChangeList(){

        List<Long> oldList = new ArrayList<Long>();
        oldList.add(1L);
        oldList.add(2L);
        oldList.add(3L);
        oldList.add(4L);
        oldList.add(5L);
        List<Long> newList = new ArrayList<Long>();
        newList.add(1L);
        newList.add(2L);
        newList.add(3L);
        newList.add(4L);
        newList.add(5L);
        List<Long> newListTemp =new ArrayList<Long>();
        newListTemp = (List<Long>) ((ArrayList<Long>) newList).clone();

        //新增加的list
       newList.removeAll(oldList);

//       减少的list
        oldList.removeAll(newListTemp);

        System.out.println(newList);

        System.out.println(oldList);


    }


    public static void main(String[] args){
//        exportDeviceExcel();
        getChangeList();
    }


}
